package TenBasicAlgorithm;
//二分
public class BinarySearchDemo {
    public static void main(String[] args) {
        int[]arr={1,3,8,10,11,67,100};
        System.out.println(BinarySearch(arr,67));

    }
    public static int BinarySearch(int[]arr ,int target){
        int l=0;
        int r=arr.length-1;
        int mid;
        while (l<=r){
            mid=(l+r)/2;
            if(arr[mid]==target){
                return mid;
            }else if(arr[mid]<target){
                l=mid+1;
            }else {
                r=mid-1;
            }
        }

            return -1;

    }
}
